﻿@COFE ?= {}

$ = jQuery
Entry = COFE.Entry
EntryItemListBase = COFE.EntryItemListBase

class HierarchyItem extends EntryItemListBase
  constructor : () ->   
    super          
    
  init: ->          
    @bind("updated", @render)
     
  update : ->
    super    
  
  fetch : ->
    @changePath(@path)

  render: ->    
    for entryItem in @folderItems     
      renderedItem = entryItem.render()   
      renderedItem.attr("value", entryItem.entry.path)
      if @App.path.param.indexOf(entryItem.entry.path) is 0 
        renderedItem.attr("selected", "selected")
      @el.append(renderedItem)
      
    @trigger("rendered", @)
    #console.log @el    
    @el.selectmenu()
    #@el.selectmenu("refresh")        
    @el.change((event) =>
      #console.log $(@el, "option:selected").attr("value")
      @App.changePath($(@el, "option:selected").attr("value"))
    )    
    @el
    

COFE.HierarchyItem = HierarchyItem